from selenium.webdriver.common.by import By
from pages.base_page import Page


class OfflineMessagePage(Page):
    ele_title = (By.ID, u'page-offlineMessageConfig-title')
    ele_error = (By.XPATH, u'//div[@role="alert"]')

    ele_use_default_offline_message_window = (By.XPATH, u'//button[@value="systemOfflineMessageWindow"]')
    ele_redirect_visitors_to_custom_page = (By.XPATH, u'//button[@value="customOfflineMessagePage"]')
    ele_trigger_a_task_bot = (By.XPATH, u'//button[@value="triggerTaskbot"]')

    ele_field_layout = (By.XPATH, u'//p[@data-tag="cardTitle"]')
    ele_offline_message_save_button = (By.XPATH, u'(//button[@data-tag="formButton"])[1]')

    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    def offline_message_page_eles_check(self):
        self.find_element(*self.ele_title).is_enabled()
        self.find_element(*self.ele_use_default_offline_message_window).is_enabled()
        self.find_element(*self.ele_redirect_visitors_to_custom_page).is_enabled()
        self.find_element(*self.ele_trigger_a_task_bot).is_enabled()
        self.find_element(*self.ele_field_layout).is_enabled()
        self.find_element(*self.ele_offline_message_save_button).is_enabled()

    def offline_message_page_button_save(self):
        self.click(self.ele_use_default_offline_message_window)
        self.click(self.ele_field_layout)
        self.click(self.ele_offline_message_save_button)
